package com.lujianfei.luggage.database.dao

import androidx.lifecycle.LiveData
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.Query
import androidx.room.Update
import com.lujianfei.babymilkmemory.database.table.HistoryTable

@Dao
interface HistoryDao {
    @Insert
    fun insert(entity: HistoryTable)

    @Update
    fun update(entity: HistoryTable)

    @Update
    fun updateAll(entities: List<HistoryTable>)

    @Query("DELETE FROM history WHERE id = :id")
    fun deleteById(id:Int)

    @Query("SELECT * FROM history WHERE id = :id")
    fun getById(id:Int): HistoryTable?

    @Query("SELECT * FROM history ORDER BY `create` DESC")
    fun getAllLiveData(): LiveData<List<HistoryTable>>

    @Query("SELECT * FROM history ORDER BY `create` DESC")
    fun getAll(): List<HistoryTable>

    @Query("SELECT * FROM history WHERE type = :type ORDER BY `create` DESC")
    fun getAllByType(type:Int): List<HistoryTable>
}